<%@ include file="includes/header.jsp"%>

<%@ page import="com.html2rss.ui.wizard.NavigateToHTMLPageAction" %>
<%@ page import="org.apache.commons.beanutils.BeanUtils" %>
<%@ page import="com.html2rss.ui.wizard.SelectFeedAction" %>


<jsp:useBean id="userPage" type="com.html2rss.models.UserPage" scope="request"/>
<jsp:useBean id="requestMethod" type="org.apache.commons.httpclient.HttpMethod" scope="request"/>


<style type="text/css">
    .html2rss_header {
        font-size: small;
        font-family: sans-serif;
        font-style: normal;
        color: black;
    }

    .html2rss_link {
        color: blue;
    }

    .highlight {
        border-style: double;
        border-width: 3px;
        border-color: black;
    }
</style>
<script type="text/javascript">
    <jsp:include page="/WEB-INF/js/browser_detect.js"/>
</script>
<script type="text/javascript">

const $$$HTML_TO_RSS_ID = "<%=NavigateToHTMLPageAction.HTML_TO_RSS_ID%>";
var $$$selected = new Array();
var $$$current = null;

function $$$onClick(event) {
    event = $$$getEvent(event);
    $$$toggle($$$getTarget(event));
}

function $$$isIndexedTag(target) {
    if (target.getAttribute($$$HTML_TO_RSS_ID)) return true; else return false;
}

function $$$toggle(target) {
    if (!$$$isIndexedTag(target)) {
        return;
    }
    if ($$$contains($$$selected, target)) {
        $$$removeTarget($$$selected, target);
        target.className = "";
    } else {
        $$$addTarget($$$selected, target);
    }
    $$$refreshDisplay();
}

function $$$refreshDisplay() {
    for (var i = 0; i < $$$selected.length; i++) {
        var a = $$$selected[i];
        a.className = "highlight";
    }
}

function $$$removeTarget(where, what) {
    var i = $$$position(where, what);
    if (i == where.length - 1) {
        where.pop();
    } else {
        where.splice(i, 1);
    }
}

function $$$addTarget(where, what) {
    where.push(what);
}

function $$$contains(where, what) {
    return $$$position(where, what) > -1;
}

function $$$position(where, what) {
    var i = 0;
    for (i = 0; i < where.length; i++) {
        var a = where[i];
        if (a.getAttribute($$$HTML_TO_RSS_ID) == what.getAttribute($$$HTML_TO_RSS_ID)) {
            return i;
        }
        i++;
    }
    return -1;
}

function $$$getTarget(event) {
    if (is_ie4up) {
        return event.srcElement;
    } else {
        return event.target;
    }
}

function $$$getEvent(event) {
    if (is_ie4up) {
        return window.event;
    } else {
        return event;
    }
}

function $$$onMouseOver(event)
{
    event = $$$getEvent(event);
    if ($$$getTarget(event) != $$$current) {
        if ($$$current != null) {
            $$$current.className = "";
        }
    }
    $$$current = $$$getTarget(event);
    if ($$$isIndexedTag($$$current)) {
        $$$current.className = "highlight";
        $$$log($$$current);
    }
    if (is_gecko) {
        event.stopPropagation();
        event.preventDefault();
    }
    $$$refreshDisplay();
    return false;
}

function $$$initEvents() {
    if (is_ie4up) {
        document.onmouseover = $$$onMouseOver;
        document.onclick = $$$onClick;
    } else {
        document.addEventListener("mouseover", $$$onMouseOver, true);
        document.addEventListener("click", $$$onClick, true);
    }
}

function $$$finish() {
    if ($$$current != null) {
        var result = "";
        for (var i = 0; i < $$$selected.length; i++) {
            result += $$$selected[i].getAttribute($$$HTML_TO_RSS_ID) + " ";
        }
        window.alert(result);
    }
}

function $$$log() {
    if (is_gecko) {
        console.log($$$current);
    }
}

function $$$initExtraction() {
    $$$initEvents();
    document.getElementById("extractRssButton").disabled = true;
    document.getElementById("selectFeedButton").disabled = false;
}

function $$$doneExtraction () {
    var url = "<%=request.getContextPath()%>/wizard/selectfeed.do?<%=SelectFeedAction.FEED_TAG_IDS%>=";
    for (var i=0; i<$$$selected.length; i++) {
        var a = $$$selected[i];
        url+=a.getAttribute($$$HTML_TO_RSS_ID);
        if (i != $$$selected.length-1) {
            url += '_';
        }
    }
    window.location.href = url;
}

</script>
<title>Navigate to your page</title>

<div class="html2rss_header">
    <h1>Step 2: Navigate to your page and extract feed</h1>
    URI: <%=requestMethod.getURI()%><br>
    <button id="extractRssButton" onclick="javascript:$$$initExtraction()">Done! Extract RSS!</button><br>
    <button id="selectFeedButton" disabled="true" onclick="javascript:$$$doneExtraction()">Done! Select Feed!</button>
</div>
<div style="position:absolute;top:200px;left:0px;width:100%">
    <%=userPage.getContent()%>
</div>

<%@ include file="includes/footer.jsp"%>